local skel = fk.CreateSkill {
  name = "emo__qimo",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__qimo"] = "祈默",
  [":emo__qimo"] = "锁定技，每当非虚拟锦囊牌对你生效后，你获得此牌，执行并删除一项：1.获得技能〖无言〗；2.失去一个其他技能；3.变更武将为“祈”。",

  ["#emo__qimo_wuyan"] = "获得技能〖无言〗",
  ["#emo__qimo_delete"] = "失去一个其他技能",
  ["#emo__qimo_change"] = "变更武将为“祈”",
  ["#emo__qimo-delete"] = "祈默：选择一个技能删去",
}

skel:addEffect(fk.CardEffectFinished, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.card.type == Card.TypeTrick
    and not (data.card:isVirtual() and #data.card.subcards == 0) and #player:getTableMark("emo__qimo_record") < 3
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getSubcardsByRule(data.card, {Card.Processing})
    if #cards > 0 then
      room:obtainCard(player, cards, true, fk.ReasonJustMove, player, skel.name)
    end
    if player.dead then return end
    local all_choices = {"#emo__qimo_wuyan", "#emo__qimo_delete", "#emo__qimo_change"}
    local choices = table.filter(all_choices, function (ch)
      return not table.contains(player:getTableMark("emo__qimo_record"), ch)
    end)
    local skills = player:getSkillNameList()
    table.removeOne(skills, skel.name)
    if #skills == 0 then
      table.removeOne(choices, "#emo__qimo_delete")
    end
    if player:hasSkill("emo__wuyan", true) then
      table.removeOne(choices, "#emo__qimo_wuyan")
    end
    if #choices == 0 then return end
    local choice = room:askToChoice(player, { choices = choices, skill_name = skel.name})
    room:addTableMark(player, "emo__qimo_record", choice)
    if choice == "#emo__qimo_wuyan" then
      room:handleAddLoseSkills(player, "emo__wuyan")
    elseif choice == "#emo__qimo_delete" then
      choice = room:askToChoice(player, { choices = skills, skill_name = skel.name, prompt = "#emo__qimo-delete", detailed = true})
      room:handleAddLoseSkills(player, "-"..choice)
    else
      local deputy = player.deputyGeneral == "moesp2__emoprincess"
      local newGeneral = "mq__qi"
      if Fk.generals[newGeneral] == nil then newGeneral = "moesp__qi" end
      room:changeHero(player, newGeneral, false, deputy, true, true, true)
    end
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "emo__qimo_record", 0)
end)

return skel
